package com.margo.project.transaction.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationEvent;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

/**
 * https://blog.csdn.net/sinat_34341162/article/details/84226437
 * https://www.cnblogs.com/AIPAOJIAO/p/9825771.html
 * @author fangxingbang
 * 		ApplicationListenerMethodTransactionalAdapter
 * 		TransactionalEventListenerFactory
 *
 */
@Component
public class MargoTransactionListener {
	private static final Logger logger = LoggerFactory.getLogger(MargoTransactionListener.class);

	@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
	public void commit(ApplicationEvent  event) {
		logger.info("transaction commit");
	}
	
	@TransactionalEventListener(phase = TransactionPhase.AFTER_ROLLBACK)
	public void rollback(ApplicationEvent  event) {
		logger.info("transaction rollback");
	}
}
